# -*- coding: cp1252 -*-
'''
Created on 18/10/2012

@author: Raphoka
'''

from Persistencia.ServicoDao import ServicoDao

class ServicoController(object):
    '''
    classdocs
    '''


    def __init__(self):
        '''
        Constructor
        '''
        self.servicoDao = ServicoDao()

    def cadastrarServico(self, servico):
        return self.__salvarServico__(servico)
        
    def editarServico(self, servico):
        return self.__salvarServico__(servico)
        
    def __salvarServico__(self, servico):
        if (servico.getId() == ''):
            return self.servicoDao.cadastrarServico(servico)
        else:
            return self.servicoDao.editarServico(servico)
    
    
        
    def pesquisarServicos(self, keyword, field):
        keyword = keyword.lower()
        field = field.lower()
        servicos = []
        if (field.find('descricao') >= 0):
            field = "SER_DESCRICAO"
            servicos = self.servicoDao.pesquisarListaServicos(keyword, field)
        return servicos

    
    def removerServico(self, servico):
        servicoDeletado = self.servicoDao.removerServico(servico)
        return servicoDeletado


    
    
    
    
